/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain one copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mikepenz.iconics.sample.views;


import ohos.agp.components.AbsButton;
import ohos.agp.components.Checkbox;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.PopupDialog;
import ohos.app.Context;

import com.mikepenz.iconics.sample.ResourceTable;

/**
 * 自定义PopupWindowDialog
 *
 * @since 2021-06-16
 */
public class PopupWindowDialog extends PopupDialog {
    private Context mContext;
    private Text mplayground;
    private Checkbox checkboxrm;
    private Checkbox checkboxsd;
    private Checkbox checkboxrfb;
    private Component contentView;
    private Popcheckstatus mPopcheckstatus;
    private boolean brm;
    private boolean sd;
    private boolean rfb;

    /**
     * 构造函数
     *
     * @param context 上下文
     * @param component 组件
     * @param popcheckstatus 状态
     * @param brm
     * @param sd
     * @param rfb
     */
    public PopupWindowDialog(Context context, Component component, Popcheckstatus popcheckstatus,
                             boolean brm, boolean sd, boolean rfb) {
        super(context, component);
        this.mContext = context;
        this.mPopcheckstatus = popcheckstatus;
        this.brm = brm;
        this.sd = sd;
        this.rfb = rfb;
        initViews();
    }

    private void initViews() {
        contentView = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_xui_popupwind_dialog, null, true);
        mplayground = (Text) contentView.findComponentById(ResourceTable.Id_tv_playground);

        checkboxrm = (Checkbox) contentView.findComponentById(ResourceTable.Id_check_box_1);
        checkboxrm.setChecked(brm);
        checkboxsd = (Checkbox) contentView.findComponentById(ResourceTable.Id_check_box_2);
        checkboxsd.setChecked(sd);
        checkboxrfb = (Checkbox) contentView.findComponentById(ResourceTable.Id_check_box_3);
        checkboxrfb.setChecked(rfb);
        initListener();
        setCustomComponent(contentView);
    }

    private void initListener() {
        checkboxrm.setCheckedStateChangedListener(new AbsButton.CheckedStateChangedListener() {
            @Override
            public void onCheckedChanged(AbsButton absButton, boolean checked) {
                mPopcheckstatus.randomize(checked);
            }
        });
        checkboxsd.setCheckedStateChangedListener(new AbsButton.CheckedStateChangedListener() {
            @Override
            public void onCheckedChanged(AbsButton absButton, boolean checked) {
                mPopcheckstatus.shadow(checked);
            }
        });
        checkboxrfb.setCheckedStateChangedListener(new AbsButton.CheckedStateChangedListener() {
            @Override
            public void onCheckedChanged(AbsButton absButton, boolean checked) {
                mPopcheckstatus.rfb(checked);
            }
        });

        mplayground.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                mPopcheckstatus.clike();
            }
        });
    }

    /**
     * 弹窗接口
     *
     * @since 2021-06-16
     */
    public interface Popcheckstatus {
        /**
         * 随机变化
         *
         * @param checked 选中
         */
        void randomize(boolean checked);

        /**
         * 阴影变化
         *
         * @param checked 选中
         */
        void shadow(boolean checked);

        /**
         * 字体变化
         *
         * @param checked 选中
         */
        void rfb(boolean checked);

        /**
         * 点击监听
         */
        void clike();
    }
}
